# 创建何使用类
class Dog:
    """ 一次模拟小狗的简单尝试 """
    # 初始化函数
    # self为Car本身
    # 类似于Java中的有参构造
    def __init__(self, name, age):
        """ 初始化属性 name 和 age """
        self.name = name
        self.age = age

    def sit(self):
        """ 模拟小狗被命令时蹲下 """
        doSomething = self.name.title() + " is now sitting."
        return doSomething

    def roll_over(self):
        """ 模拟小狗被命令时打滚 """
        doSomething = self.name.title() + " rolled over!"
        return doSomething


# 根据类创建实例
# 与java最为不同之处：不需要为添加new关键字
my_dog = Dog('willie', 6)
print("My dog's name is " + my_dog.name.title() + ".")
print("My dog is " + str(my_dog.age) + " years old.")

# command = input("\n输入你的命令：")

# if command == "sit":
#     print(my_dog.sit())
# elif command == "roll_over":
#     print(my_dog.roll_over())


class Car:
    """ 一次模拟汽车的简单尝试 """
    # self为Car本身
    def __init__(self, make, model, year):
        """ 初始化描述汽车的属性 """
        self.make = make
        self.model = model
        self.year = year

    def get_descriptive_name(self):
        """ 返回整洁的描述性信息 """
        long_name = str(self.year) + ' ' + self.make + ' ' + self.model
        return long_name.title()

    def fill_gas_tank(self):
        return


my_new_car = Car('audi', 'a4', 2016)
print(my_new_car.get_descriptive_name())


class Test:
    def test(self):
        return "Test"


# 继承Car类（在声明类的括号中添加要继承的类）
class ElectricCar(Car):
    """ 电动汽车的独特之处 """
    def __init__(self, make, model, year):
        """ 初始化父类的属性 """
        # 在子类的初始化方法中调用父类的初始化方法
        super().__init__(make, model, year)
        # 为子类添加属性
        self.battery_size = 70
        # 添加类实例作为属性
        self.test = True

    # 为子类添加方法
    def describe_battery(self):
        text = "This car has a " + str(self.battery_size) + "-kWh battery."
        return text

    # 重写父类的方法
    def fill_gas_tank(self):
        """ 电动汽车没有油箱 """
        info = "This car doesn't need a gas tank!"
        return info


my_tesla = ElectricCar('tesla', 'model s', 2016)
# 测试继承
print(my_tesla.get_descriptive_name())
# 测试为子类添加的属性以及方法
print(my_tesla.describe_battery())
# 测试子类重写父类的方法
print(my_tesla.fill_gas_tank())
# 测试实例作为属性
print(my_tesla.test)

# 导入多个类（一般导入类的语句要放在程序的开头）
from Module import Car, Dog

my_new_car = Car('audi', 'ao4', 12323)
print(my_new_car.get_descriptive_name())
my_dog = Dog('哈哈', 10)
print(my_dog.name)

